<template>
  <div>
    <zh-form :span="8" ref="formInfo" :colmun="1" :labelCol="labelColBase"
             :wrapperCol="wrapperColBase" :rules="rules" :model="formInfo" labelAlign="right">

      <zh-card title="基本信息" style="width:100%">
        <zh-row>
          <zh-input
              prop="h0502"
              type="select"
              label="区划"
              :options="dictData.xzqh"
              :defaultFields="{ label: 'dictValue', value: 'dictKey' }"
              v-model="formInfo.h0502"
          ></zh-input>
          <zh-input
              prop="h0504"
              type="text"
              label="工程名称"
              v-model="formInfo.h0504"
          ></zh-input>
          <zh-input
              prop="h0512"
              type="text"
              label="工程地址"
              v-model="formInfo.h0512"
          ></zh-input>
          <zh-input
              prop="h0506"
              type="text"
              label="责任单位"
              v-model="formInfo.h0506"
          ></zh-input>
          <zh-input
              prop="h0507"
              type="text"
              label="责任人"
              v-model="formInfo.h0507"
          ></zh-input>
          <zh-input
              prop="h0510"
              type="text"
              label="项目投资"
              v-model="formInfo.h0510"
          ></zh-input>
          <zh-input
              prop="h0511"
              type="date"
              label="完工时间"
              v-model="formInfo.h0511"
          ></zh-input>
          <zh-input
              prop="h0508"
              type="select"
              label="项目状态"
              :options="dictData.h0508"
              :defaultFields="{ label: 'dictValue', value: 'dictKey' }"
              v-model="formInfo.h0508"
          ></zh-input>
          <zh-input
              prop="h0513"
              type="text"
              label="占地面积"
              v-model="formInfo.h0513"
          ></zh-input>
          <zh-input
              prop="h0514"
              type="text"
              label="建筑面积"
              v-model="formInfo.h0514"
          ></zh-input>
          <zh-input
              prop="b0106"
              type="select"
              label="年代"
              :options="dictData.b0106"
              :defaultFields="{ label: 'dictValue', value: 'dictKey' }"
              v-model="formInfo.b0106"
          ></zh-input>
          <zh-input
              prop="h1706"
              type="select"
              :options="dictData.h1706"
              :defaultFields="{ label: 'dictValue', value: 'dictKey' }"
              label="项目进度"
              v-model="formInfo.h1706"
          ></zh-input>
          <zh-input label="点位名称" show-search :labelInValue="true" :filter-option="false"
                    :not-found-content="fetching ? undefined : null"
                    :defaultFields="{label: 'b0102',value: 'b0101'}" type="select" placeholder="请输入点位名称"
                    v-model="b01"
                    :options="b01DataList"
                    @search="handleSearch"
                    @change="handleChange">
            <a-spin v-if="fetching" slot="notFoundContent" size="small"/>
          </zh-input>
        </zh-row>
        <div class="title" style="margin-bottom: 10px">
          <p>多媒体</p>
        </div>
        <ep-button
            style="margin-top: 10px"
            size="default"
            icon="add.svg"
            @click="
            () => {
              this.addModel();
            }
          "
        >新增模块
        </ep-button>
        <div v-for="(e, h27Index) in h27VOList" :key="h27Index" v-if="render">
          <div class="operate">
            <div style="width: 10%">标题</div>
            <div style="width: 90%">
              <a-input placeholder="请输入标题" v-model="e.h2702" :disabled="disabled"/>
            </div>
          </div>
          <div class="operate" style=" ">
            <div style="width: 10%;">简介</div>
            <div style="width: 90%">
              <a-textarea placeholder="请输入简介" :auto-size="{ minRows: 3, maxRows: 6 }" v-model="e.h2703"
                          :disabled="disabled"/>
            </div>
          </div>
          <div class="operate">
            <div style="width: 100%; padding: 0 20px">
<!--                        <div class="title" style="margin-bottom: 10px">-->
<!--                          <p>多媒体</p>-->
<!--                        </div>-->
              <div style="width: 100%;display: block">
                <div style="text-align: right;width: 100%">
                  <ep-button
                      icon="add.svg"
                      size="small"
                      type="primary"
                      @click="addMediaInfo(h27Index)"
                      :disabled="disabled"
                  >添加
                  </ep-button>
                  <ep-button
                      style="margin-left: 10px"
                      size="small"
                      type="danger"
                      icon="del.svg"
                      @click="removeModel(h27Index)"
                  >删除模块
                  </ep-button>
                </div>
                <div>
                  <ul class="media-wrap">
                    <li v-for="(item, index) in e.h25VOList" :key="index">
                      <div class="item special">
                        <div class="desc">序号</div>
                        <p>{{ item.h2507 }}</p>
                      </div>
                      <div class="item">
                        <div class="desc">名称</div>
                        <p>{{ item.h2503 }}</p>
                      </div>
                      <div class="item">
                        <div class="desc">文件名称</div>
                        <p>{{ item.h2505 }}</p>
                      </div>
                      <div class="item">
                        <div class="desc">缩略图</div>
                        <img
                            v-if="item.h2504"
                            :src="fileShowUrl + item.h2504"
                            @click="checkImg(item.h2504)"
                            alt=""
                        />
                      </div>

                      <div class="item">
                        <div class="desc"></div>
                        <div class="btn-wrap">
                          <ep-button
                              size="small"
                              @click="editMediaInfo(item, index,h27Index)"
                              :disabled="disabled"
                          >编辑
                          </ep-button>
                          <ep-button
                              size="small"
                              type="danger"
                              style="margin-left: 15px"
                              @click="deleteMediaInfo(index,h27Index)"
                              :disabled="disabled"
                          >删除
                          </ep-button>
                          <ep-button size="small"
                                     @click="dowloadFile(item)"
                                     style="margin-left: 15px"
                          >
                            下载
                          </ep-button>
                        </div>
                      </div>
                    </li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
        </div>
        <a-modal
            :title="modalTitle"
            centered
            style="top: 20px"
            width="50%"
            destroyOnClose
            v-model="visible"
            cancelText="关闭"
            okText="保存"
            @ok="handleForm"
        >
          <development-media ref="mediaInfoItem"/>
        </a-modal>
  </zh-card>
  </zh-form>
  <zh-card style="width:100%" title="新增属性字段设置">
    <!-- <a-form-model
        ref="h06VOList"
        :label-col="labelCol"
        :wrapper-col="wrapperCol">

      <a-form-model-item
          v-for="(item, index) in formInfo.h06VOList"
          :key="index"
      >
        <div class="list-item">
          <div class="list-item-index">{{ index + 1 }}.</div>
          <a-input
              :size="size"
              v-model="item.h0603"
              placeholder="请输入"
              style="width: 50%; margin-right: 8px"
          />
          <a-button :size="size" type="link" icon="delete" @click="removeSpecialInfo(index)">删除</a-button>
          <a-select
              :size="size"
              style="width: 7vw;margin-left: 15px"
              v-model="item.h0602"
              @change="h0602Change(item,index)"
          >
            <a-select-option
                v-for="(item3, index3) in h0602Dict"
                :value="item3.dictKey"
                :key="index3"
            >{{ item3.dictValue }}</a-select-option
            >
          </a-select>
          <a-checkbox :size="size" style="margin-left: 15px" v-model="item.h0604">必填</a-checkbox>
        </div>

        <a-form-model class="sub-form" ref="optionList" :model="item.optionList"
                      :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-form-model-item
              v-for="(item2, index2) in item.optionList"
              :key="index2"
              :label="item2.label"
          >
            <div class="list-item">
              <a-input
                  v-model="item2.h0702"
                  :size="size"
                  placeholder="请输入选项名称"
                  style="width: 40%; margin-right: 8px"
                  @blur="h0702Change"
              />
              <a-button :size="size" type="link" icon="delete" @click="removeOption(index2,index)">删除</a-button>
              <a-checkbox :size="size" @change="h0703Change" v-if="item2.h0703 != null"  style="margin-left: 15px" v-model="item2.h0703">设为默认项</a-checkbox>
            </div>
          </a-form-model-item>

        </a-form-model>
        <div v-if="item.h0602 === '4' || item.h0602 === '5'">
          <a-button :size="size" type="link" icon="plus" @click="addOption(item,index)">添加单项</a-button>
          <a-divider type="vertical" />
          <a-button :size="size" type="link" @click="addOptionOther(item,index)">添加其他</a-button>
        </div>
      </a-form-model-item>
      <a-form-model-item >
        <a-button type="dashed" icon="plus" style="width: 50%" @click="addSpecialInfo">新增字段</a-button>
      </a-form-model-item>
    </a-form-model> -->
    <zh-table ref="sxTable" type="default" model="model" :columns="columns" :height="350"
              :toolbarConfig="toolbarConfig" :disabled="false" :data="formInfo.h06VOList">
      <template #toolbar_tools>
        <a-tooltip placement="top" title="新增">
          <a-icon style="font-size:x-large;font-weight: bolder;margin-right: 10px" @click="addSx"
                  type="plus-circle"/>
        </a-tooltip>
      </template>
      <template #operate="{ row }">
        <div class="alert-message">
          <i class="fa fa-exclamation-circle alert-message-icon"></i>
          <span class="alert-message-content">
                <a-tooltip placement="top">
                  <template slot="title">
                    <span>删除</span>
                  </template>
                  <a-popconfirm placement="left" title="是否确定删除该数据?" ok-text="确定" cancel-text="取消"
                                @confirm="removeSx(row) ">
                    <a-icon style="padding-right:10px;color: #FF0000;cursor: pointer;" theme="filled" type="delete">
                    </a-icon>
                  </a-popconfirm>
                </a-tooltip>
              </span>
        </div>
      </template>
      <template #h0603_edit="{ row }">
        <zh-input style="width: 100%;" v-model="row.h0603"></zh-input>
      </template>
      <template #h0603_default="{ row }">
        {{ row.h0603 }}
      </template>
      <template #h0602_edit="{ row }">
        <zh-input style="width: 100%;" v-model="row.h0602"></zh-input>
      </template>
      <template #h0602_default="{ row }">
        {{ row.h0602 }}
      </template>
    </zh-table>
  </zh-card>
  <zh-card style="width:100%" title="报审设置">
    <!-- <a-form-model
        ref="h08VOList"
        :label-col="labelCol"
        :wrapper-col="wrapperCol">

      <a-form-model-item
          v-for="(item4, index4) in formInfo.h08VOList"
          :key="index4"
      >
        <div class="list-item">
          <div class="list-item-index">{{ index4 + 1 }}.</div>
          <a-input
              :size="size"
              v-model="item4.h0802"
              placeholder="请输入"
              style="width: 50%; margin-right: 8px"
          />
          <a-button :size="size" type="link" icon="delete" @click="removeNodeInfo(index4)">删除</a-button>
        </div>
      </a-form-model-item>
      <a-form-model-item >
        <a-button type="dashed" icon="plus" style="width: 50%" @click="addNodeInfo">新增节点</a-button>
      </a-form-model-item>
    </a-form-model> -->
    <ep-button style="margin:15px" @click="addNode()">新增节点</ep-button>
    <div v-if="h08VOFlag">
      <zh-form
          ref="h08VOList"
          v-for="(item, index) in formInfo.h08VOList"
          :key="index"
      >
        <zh-input
            :value="item.h0802"
            :key="index"
            prop="h0802" :label="'节点'+(index+1)"
            v-model="item.h0802">
        </zh-input>
        <a icon="delete" style="margin:7px" @click="removeNodeInfo(index)">删除</a>
      </zh-form>
    </div>
  </zh-card>
  </div>
</template>

<script>
import modal from 'ant-design-vue/es/modal'
import {fileDownloadUrl, fileShowUrl, getBatchDict} from "@/services/system/api"
import {developProjectAdd, getB01DataList, getDevelopProjectDetails} from '@/services/system/whdngxlApi'
import {TreeSelect} from "ant-design-vue";
import moment from "moment";
import {mapGetters} from "vuex";
import developmentMedia from "@/pages/system/form/developmentMedia";

const SHOW_PARENT = TreeSelect.SHOW_PARENT;
let timeout;
let currentValue;
export default {
  name: "DevelopProjectAddForm",
  components: {
    developmentMedia,
  },
  computed: {
    ...mapGetters(['size']),
  },
  props: {
    listQuery: {
      type: Function,
      default: null
    },
  },
  data() {
    return {
      h08VOFlag: true,
      toolbarConfig: {
        slots: {
          tools: 'toolbar_tools'
        }
      },
      formInfo: {
        h0501: '',
        h0502: '',
        h0503: '',
        h0504: '',
        h0505: '',
        h0507: '',
        h0508: '',
        h0510: '',
        h0511: '',
        h0512: '',
        h0513: '',
        h0514: '',
        h0515: '',
        h0516: '',
        b0106: '',
        h1706: '',
        h25VOList: [],
        h06VOList: [],
        h06VOListDel: [],
        h08VOList: [],
        h08VOListDel: [],
      },
      fetching: false,
      b01DataList: [],
      b01: undefined,
      /*mediaFieldRuleFrom:{
        h2501: 'b0201',
        h0501: 'k0201',
        h2502: 'b0203',
        h2503: 'b0202',
        h2504: 'b0206',
        h2505: 'b0205',
        h2506: 'b0207'
      },*/
      h25Index: -1,
      h2507Num: 0,
      fileShowUrl,
      render: true,
      h25VOList: [],
      h27VOList: [{
        h2702: '',
        h2703: '',
        h25VOList: [],
      }],
      h27VOItem: {
        h2702: '',
        h2703: '',
        h25VOList: [],
      },
      h27Index: -1,
      h25VOListForEdit: [],
      h25VOListForDel: [],
      h25VOListDelMOdel:[],
      modalTitle: "",
      disabled: false,
      visible: false,
      rules: {},
      dictData: {
        xzqh: [],
        h0505: [],
        h0508: [],
        b0106: [],
        h1706: [],
      },
      taskAreaTree: [],
      SHOW_PARENT,
      // d0212Show:true,
      h0602Dict: [
        {dictKey: "1", dictValue: "数字"},
        {dictKey: "2", dictValue: "文本"},
        {dictKey: "3", dictValue: "日期"},
        {dictKey: "4", dictValue: "选项(单选)"},
        {dictKey: "5", dictValue: "选项(多选)"},
        {dictKey: "6", dictValue: "多媒体"},
        {dictKey: "7", dictValue: "定位"},
        {dictKey: "8", dictValue: "手机号"},
      ],
      labelCol: {span: 2},
      wrapperCol: {span: 22},
      labelColBase: {
        xs: {span: 24},
        sm: {span: 8},
      },
      wrapperColBase: {
        xs: {span: 24},
        sm: {span: 16},
      },
      columns: [
        {
          title: '属性名称',
          dataIndex: 'h0603',
          key: 'h0603',
          editRender: {}, slots: {edit: 'h0603_edit', default: 'h0603_default'}
        },
        {
          title: '属性值',
          dataIndex: 'h0602',
          key: 'h0602',
          editRender: {}, slots: {edit: 'h0602_edit', default: 'h0602_default'}
        },
        {field: 'operate', title: '操作', align: 'center', maxwidth: 120, fixed: 'right', slots: {default: 'operate'}}
      ],
    }
  },

  created() {
    const params2 = {};
    params2.dictFields = "xzqh,h0508,h0505,b0106,h1706";
    this.$http.post(getBatchDict, params2).then((res) => {
      this.dictData = res.result;
    });
  },
  methods: {
    fetch(value, callback) {
      if (timeout) {
        clearTimeout(timeout);
        timeout = null;
      }
      currentValue = value;

      function fake(that) {
        that.fetching = true
        if (value) {
          that.$http.post(getB01DataList, {b0102: value, b0122: that.formInfo.b0122}).then(res => {
            console.log(res)
            callback(res.result);
          }).catch((error) => {
            console.log(JSON.stringify(error))
          }).finally(() => {
            that.fetching = false
          })
        }
      }

      timeout = setTimeout(fake(this), 300);
    },
    handleSearch(value) {
      this.fetch(value, data => (this.b01DataList = data));
    },
    handleChange(option) {
      console.log(option);
      this.b01 = option
    },
    initData(data) {
      //编辑
      if (data.h0501) {
        this.b01DataList = [{b0101: data.b0101, b0102: data.b0102}]
        this.b01 = {key: data.b0101, label: data.b0102}
        const params = {}
        params.h0501 = data.h0501
        setTimeout(() => {
          this.$http.post(getDevelopProjectDetails, params).then((res) => {
            this.formInfo = res.result
            this.formInfo.h06VOListDel = []
            this.formInfo.h08VOListDel = []

            this.h27VOList = res.result.h27VOList ? res.result.h27VOList : []
            /*for (const item of h25VOList) {
              const mediaInfo = {}
              for (const itemKey in item) {
                if (itemKey === 'h2503') {
                  if (item[itemKey] === '1') {
                    mediaInfo.b0202Name = '图片'
                  }
                }
                if (this.mediaFieldRuleFrom[itemKey]) {
                  mediaInfo[this.mediaFieldRuleFrom[itemKey]] = item[itemKey]
                }
              }
              this.h25VOList.push(mediaInfo)
            }*/
          }).catch((error) => {
          }).finally(() => {
          })
        }, 50)
      }
    },
    getData() {
      const params = {};
      Object.assign(params, this.formData);
      if (this.h25VOList.length > 0) {
        const h25VOList = []
        // eslint-disable-next-line no-debugger
        debugger
        for (let e of this.h25VOList) {
          if (!e.b0201) {
            const h25VO = {}
            for (const itemKey in e) {
              if (this.mediaFieldRuleTo[itemKey]) {
                h25VO[this.mediaFieldRuleTo[itemKey]] = e[itemKey]
              }
            }
            h25VOList.push(h25VO)
          }
        }
        params.h25VOList = h25VOList
      }
      if (this.h25VOListForEdit.length > 0) {
        const h25VOListForEdit = []
        for (let e of this.h25VOListForEdit) {
          const h25VO = {}
          for (const itemKey in e) {
            if (this.mediaFieldRuleTo[itemKey]) {
              h25VO[this.mediaFieldRuleTo[itemKey]] = e[itemKey]
            }
          }
          h25VOListForEdit.push(h25VO)
        }
        params.h25VOListForEdit = h25VOListForEdit
      }
      if (this.h25VOListForDel.length > 0) {
        const h25VOListForDel = []
        for (let e of this.h25VOListForDel) {
          const h25VO = {}
          for (const itemKey in e) {
            if (this.mediaFieldRuleTo[itemKey]) {
              h25VO[this.mediaFieldRuleTo[itemKey]] = e[itemKey]
            }
          }
          h25VOListForDel.push(h25VO)
        }
        params.h25VOVOListForDel = h25VOListForDel
      }
      return params;
    },
    h0702Change() {
      this.$forceUpdate(); //重新强制渲染
    },
    h0703Change() {
      this.$forceUpdate(); //重新强制渲染
    },
    //移除专项表单内容
    removeSpecialInfo(index) {
      modal.confirm({
        title: "确认删除吗？",
        onOk: () => {
          if (this.formInfo.h06VOList[index].h0601) {
            const item = JSON.parse(JSON.stringify(this.formInfo.h06VOList[index]));
            this.formInfo.h06VOListDel.push(item);
          }
          this.formInfo.h06VOList.splice(index, 1);
        },
        onCancel: () => {
        },
      })
    },
    //添加专项表单内容
    addSpecialInfo() {

      this.formInfo.h06VOList.push({
        h0602: '',
        h0603: '',
        h0604: true,
      })
    },
    //添加节点设置内容
    addNodeInfo() {
      this.formInfo.h08VOList.push({
        h0802: '',
      })
    },
    //添加节点设置内容
    addNode() {
      this.h08VOFlag = false;
      if(this.formInfo.h08VOList === undefined){
        this.formInfo.h08VOList = []
      }
      this.formInfo.h08VOList.push({
        h0802: '',
      })
      this.$nextTick(()=>{
        this.h08VOFlag = true
      })
    },
    //新增属性字段
    addSx() {
      if (this.formInfo.h06VOList != undefined) {
        Object.assign(this.formInfo.h06VOList, this.$refs.sxTable.getTableData().tableData);
      }
      debugger
      this.$refs.sxTable.insert({});
    },
    //删除属性
    removeSx(row) {
      this.formInfo.h06VOListDel.push(row);
      this.$refs.sxTable.remove(row)
    },
    getListSize(list) {
      console.log(list)
      this.h2507Num = 0;
      list.forEach((item) => {
        debugger
        if (item.h2507 > this.h2507Num) {
          this.h2507Num = item.h2507;
        }
      });
      if (this.h2507Num < list.length) {
        this.h2507Num = list.length - 1;
      }
      this.h2507Num++;
    },
    checkImg(showId) {
      let url = this.fileShowUrl + showId;
      window.open(url, "_blank");
    },
    //新增
    addMediaInfo(index) {
      debugger
      this.h27Index = index
      this.modalTitle = "新增";
      this.visible = true;
      this.$nextTick(() => {
        this.$refs.mediaInfoItem.editFlag = false
        this.getListSize(this.h27VOList[this.h27Index].h25VOList);
        this.$refs.mediaInfoItem.h2507Num = this.h2507Num;
        this.$refs.mediaInfoItem.init(null);
      });
    },
    //编辑
    editMediaInfo(row, index,h27Index) {
      debugger
      this.modalTitle = "编辑";
      this.editIndex = index;
      this.h27Index = h27Index;
      this.visible = true;
      this.$nextTick(() => {
        this.h27Index = h27Index;
        this.$refs.mediaInfoItem.editFlag = this.editFlag
        if (row.h2501) {
          row.flag = "edit";
        }
        this.$refs.mediaInfoItem.init(row);
      });
    },
    deleteMediaInfo(index,h27Index) {
      modal.confirm({
        title: "确认删除吗？",
        onOk: () => {
          debugger
          if ( this.h27VOList[h27Index].h25VOList[index].h2501) {
            const item = JSON.parse(JSON.stringify(this.h27VOList[h27Index].h25VOList[index]));
            item.flag = "delete";
            this.h25VOListForDel.push(item);
            console.log(this.h25VOListForDel)
          }
          this.h27VOList[h27Index].h25VOList.splice(index, 1);
        },
        onCancel: () => {
        },
      });
    },
    dowloadFile(row) {
      let downloadUrl = fileDownloadUrl
      if (row.h2504.length > 0) {
        downloadUrl += row.h2504
      }
      let a = document.createElement('a');
      a.href = downloadUrl;
      a.click();
    },
    //确定
    handleForm() {
      debugger
      var mediaInfoItem = this.$refs.mediaInfoItem.mediaInfoItem;
      if (this.modalTitle === "新增") {
        mediaInfoItem.flag = "save";
        this.h27VOList[this.h27Index].h25VOList.push(mediaInfoItem);
        console.log(this.h27VOList)
      } else {
        if (mediaInfoItem.flag === 'edit') {
          this.h27VOList[this.h27Index].h25VOList.splice(this.editIndex, 1, mediaInfoItem);
        }
      }
      this.$nextTick(() => {
        this.visible = false;
      });
    },
    //移除节点设置内容
    removeNodeInfo(index) {
      modal.confirm({
        title: "确认删除吗？",
        onOk: () => {
          if (this.formInfo.h08VOList[index].h0801) {
            debugger
            const item = JSON.parse(JSON.stringify(this.formInfo.h08VOList[index]));
            this.formInfo.h08VOListDel.push(item);
          }
          this.formInfo.h08VOList.splice(index, 1);
        },
        onCancel: () => {
        },
      })
    },
    //移除单选项多选项内容
    removeOption(index2, index) {
      if (this.formInfo.h06VOList[index].optionListDel === null || this.formInfo.h06VOList[index].optionListDel === undefined) {
        this.formInfo.h06VOList[index].optionListDel = []
      }

      let length = this.formInfo.h06VOList[index].optionList.length
      for (let i = 0; i < length; i++) {
        if (this.formInfo.h06VOList[index].optionList[i].h0704 === '1') {
          length = length - 1
        }
      }

      if (this.formInfo.h06VOList[index].optionList[index2].h0704 !== '1' && length <= 2) {
        this.$message.warn("选项至少需要保留两个！");
        return
      }

      modal.confirm({
        title: "确认删除吗？",
        onOk: () => {
          if (this.formInfo.h06VOList[index].optionList[index2].h0701) {
            const item = JSON.parse(JSON.stringify(this.formInfo.h06VOList[index].optionList[index2]));
            this.formInfo.h06VOList[index].optionListDel.push(item);
          }
          this.formInfo.h06VOList[index].optionList.splice(index2, 1)
          this.$forceUpdate(); //重新强制渲染
        },
        onCancel: () => {
        },
      })
    },
    //添加单选项多选项内容
    addOption(item, index) {
      let length = 0; //排除其他后的选项个数
      for (let i = 0; i < this.formInfo.h06VOList[index].optionList.length; i++) {
        if (this.formInfo.h06VOList[index].optionList[i].h0704 !== '1') {
          length = length + 1
        }
      }
      let num = length + 1
      let option = {}
      if (item.h0602 === '4') {
        option = {label: '选项' + num, h0702: '', h0703: false}
      } else {
        option = {label: '选项' + num, h0702: '',}
      }

      this.formInfo.h06VOList[index].optionList.push(JSON.parse(JSON.stringify(option)))
      this.$forceUpdate(); //重新强制渲染
    },
    //添加“其他”选项
    addOptionOther(item, index) {
      for (let i = 0; i < this.formInfo.h06VOList[index].optionList.length; i++) {
        let option = this.formInfo.h06VOList[index].optionList[i]
        if (option.h0704 === '1') {
          this.$message.warn("已经有其他选项，不能再添加！");
          return
        }
      }
      const optionOther = {label: '其他', h0702: '', h0704: '1'}
      this.formInfo.h06VOList[index].optionList.push(JSON.parse(JSON.stringify(optionOther)))
      this.$forceUpdate(); //重新强制渲染
    },
    //日期选择器禁用的日期
    onDisabledDate(current) {
      const time = moment().endOf('day').subtract(1, 'days')
      return current < time
    },
    //属性字段类型h0602改变事件
    h0602Change(item, index) {
      this.formInfo.h06VOList[index].optionList = []

      if (item.h0602 === '4' || item.h0602 === '5') {
        let defaultOption = []
        if (item.h0602 === '4') {
          defaultOption = [{label: '选项1', h0702: '', h0703: false}, {label: '选项2', h0702: '', h0703: false}]
        } else {
          defaultOption = [{label: '选项1', h0702: ''}, {label: '选项2', h0702: ''}]
        }

        this.formInfo.h06VOList[index].optionList = JSON.parse(JSON.stringify(defaultOption))
      }
    },
    confirm() {
      if (this.formInfo.h0502 == '' || this.formInfo.h0502 == null) {
        modal.warn({title: "提示", content: "区划不能为空"});
        return;
      }
      if (this.formInfo.h0504 == '' || this.formInfo.h0504 == null) {
        modal.warn({title: "提示", content: "工程名称不能为空"});
        return;
      }
      console.log(this.formInfo.h06VOList)
      console.log(this.$refs.sxTable.getTableData().tableData)
      if (this.formInfo.h06VOList != undefined || this.$refs.sxTable.getTableData().tableData.length != 0) {
        if (this.formInfo.h06VOList == undefined) {
          this.formInfo.h06VOList = []
        }
        Object.assign(this.formInfo.h06VOList, this.$refs.sxTable.getTableData().tableData);
      }
      // for(let i=0;i<this.formInfo.h06VOList.length;i++){
      //   if(this.formInfo.h06VOList[i].h0602 == null || this.formInfo.h06VOList[i].h0602 == ''){
      //     modal.warn({title: '提示', content: '属性字段类型不能为空'})
      //     return
      //   }
      //   if(this.formInfo.h06VOList[i].h0603 == null || this.formInfo.h06VOList[i].h0603 == ''){
      //     modal.warn({title: '提示', content: '属性字段名称不能为空'})
      //     return
      //   }
      //   if(this.formInfo.h06VOList[i].optionList){
      //     for(let j=0;j<this.formInfo.h06VOList[i].optionList.length;j++){
      //       if(this.formInfo.h06VOList[i].optionList[j].h0702 == null || this.formInfo.h06VOList[i].optionList[j].h0702 == ''){
      //         modal.warn({title: '提示', content: '类型为单选或多选时，选项名称不能为空'})
      //         return
      //       }
      //     }
      //   }
      // }
      if (this.formInfo.h08VOList && this.formInfo.h08VOList.length > 0) {
        for (let i = 0; i < this.formInfo.h08VOList.length; i++) {
          if (this.formInfo.h08VOList[i].h0802 == null || this.formInfo.h08VOList[i].h0802 == '') {
            modal.warn({title: '提示', content: '节点名称不能为空'})
            return
          }
        }
      }
      this.$loading.show('正在处理数据,请等待...')
      const params = Object.assign(this.formInfo)
      params.b0101=this.b01.key
      params.b0102=this.b01.label
      params.h25VOList = this.h25VOList
      params.h27VOList = this.h27VOList
      params.h25VOListForDel = this.h25VOListForDel
      params.h25VOListDelMOdel=this.h25VOListDelMOdel
      setTimeout(() => {
        this.$http.post(developProjectAdd, params).then((res) => {
          this.$message.info('保存成功')
          this.$emit("handleCancel")
          if (this.listQuery) {
            this.listQuery()
          }
        }).catch((error) => {
          console.log(JSON.stringify(error))
        }).finally(() => {
          this.$loading.hide()
        })
      }, 50)
    },
    addModel() {
      if (this.h27VOList == undefined) {
        this.h27VOList = []
      }
      console.log(this.h27VOItem)
      this.h27VOList.push(JSON.parse(JSON.stringify(this.h27VOItem)))
      this.render = false
      setTimeout(() => {
        //页面无法更新渲染，先用v-if处理
        this.render = true
      }, 100)
    },
    removeModel(h27Index){
      modal.confirm({
        title: "确认删除吗？",
        onOk: () => {
          this.h25VOListDelMOdel.push(this.h27VOList[h27Index])
          this.h27VOList.splice(h27Index,1)
        },
        onCancel: () => {
        },
      });
      console.log(this.h25VOListDelMOdel)
    }
  }
}
</script>

<style scoped lang="less">
.media-wrap {
  margin-top: 15px;

  li {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 15px;

    .item {
      flex: 0 0 auto;
      width: 18%;

      .desc {
        width: 100%;
        height: 21px;
        line-height: 21px;
        font-weight: bold;
        margin-bottom: 10px;
      }

      p {
        width: 100%;
        height: 32px;
        line-height: 30px;
        padding: 0 10px;
        border: 1px solid #3e9fc8;
        border-radius: 4px;
        box-sizing: border-box;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .btn-wrap {
        text-align: center;
      }

      img {
        width: auto;
        height: 90px;
        max-width: 98%;
        vertical-align: middle;
        cursor: pointer;
      }

      &.special {
        width: 5%;
      }
    }
  }
}

.title {
  display: flex;
  line-height: 32px;
  padding: 5px 0px;

  p {
    flex: 0 0 auto;
    color: #2466d0;
    font-weight: bold;
    font-size: 20px;
  }

  span {
    flex: 0 0 auto;
    margin-left: 8px;
    color: red;
  }
}

.list-item {
  display: flex;

  .list-item-index {
    width: 36px;
    font-size: 18px;
  }
}

.operate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 10px;


  > div {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
  }


}

.sub-form {
  margin-top: 15px;
}
</style>
